package com.tp.checkly.dao.impl;

import java.util.Arrays;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import org.springframework.orm.jdo.support.JdoDaoSupport;
import org.springframework.transaction.annotation.Transactional;

import com.tp.checkly.dao.ChecklistDao;
import com.tp.checkly.domain.Task;

public class ChecklistDaoImpl extends JdoDaoSupport implements ChecklistDao {
	
	@SuppressWarnings("unchecked")
	@Transactional
	public List<Task> getChecklist(String userid)
	{
		PersistenceManager pm = getPersistenceManager();
		Query query = pm.newQuery(Task.class);
		query.setFilter("userId == pUserId");
		query.declareParameters("String pUserId");
		List<Task> tasks = (List<Task>) query.execute(userid);
		
		return tasks;
	}
	
	@Transactional
	public void saveChecklist(List<Task> tasks)
	{
		PersistenceManager pm = getPersistenceManager();
		pm.makePersistentAll(tasks);
	}
	
}
